package com.junzhiit.nengji.api.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.AreaService;
import com.junzhiit.nengji.api.service.ColumnService;
import com.junzhiit.nengji.api.service.OrdersService;
import com.junzhiit.nengji.api.web.vo.AreaVO;
import com.junzhiit.nengji.api.web.vo.ListVO;
import com.junzhiit.nengji.api.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/column")
public class ColumnController extends BaseController {
	
	@Autowired
	private ColumnService columnService;
	
	@Autowired
	private AreaService areaService;
	
	@Autowired
	private OrdersService ordersService;
	
	/*@ApiOperation(value = "查询栏目中模块的所有内容")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO findAll(String userId,String columnCode,String cityCode) {
		AssertUtil.notBlank(columnCode, "columnCode is required.");
		AssertUtil.notBlank(cityCode, "cityCode is required.");
		return columnService.findColumnInfo(userId,columnCode,cityCode);
	}*/
	
	@ApiOperation(value = "首页(广告)")
	@RequestMapping(value = "/home/advertise",method = RequestMethod.GET)
	public ResultVO homeAdvertise(String columnCode) {
		AssertUtil.notBlank(columnCode, "columnCode is required.");
		return columnService.home(columnCode);
	}
	
	@ApiOperation(value = "首页(乐鸽精选商品)")
	@RequestMapping(value = "/home/goods",method = RequestMethod.GET)
	public ListVO homeGoods(String userId,String columnCode,String modulesCode,String cityCode,Integer pageNumber,Integer maxPageRow) {
		AssertUtil.notBlank(columnCode, "columnCode is required.");
//		AssertUtil.notBlank(cityCode, "cityCode is required.");
		AssertUtil.notBlank(modulesCode, "modulesCode is required.");
		AssertUtil.notNull(pageNumber, "pageNumber is required.");
		AssertUtil.notNull(maxPageRow, "maxPageRow is required.");
		//return columnService.homeGoods(userId, columnCode, modulesCode, cityCode, pageNumber, maxPageRow);
  	    return columnService.homeGoods(columnCode, modulesCode, pageNumber, maxPageRow);
	}
	
	@ApiOperation(value = "查询栏目的所有内容(新)")
	@RequestMapping(value = "/info",method = RequestMethod.GET)
	public ListVO columnInfo(String userId,String columnCode,String cityCode,Integer pageNumber,Integer maxPageRow) {
		AssertUtil.notBlank(columnCode, "columnCode is required.");
		AssertUtil.notBlank(cityCode, "cityCode is required.");
		return columnService.columnInfo(userId, columnCode, cityCode, pageNumber, maxPageRow);
	}
	
	@ApiOperation(value = "查询城市")
	@RequestMapping(value = "/get/area", method = RequestMethod.GET)
	public ResultVO getArea(AreaVO areaVO) {
		return areaService.findInfo(areaVO);
	}
	
	@ApiOperation(value = "用户订单统计")
	@RequestMapping(value = "/order/count", method = RequestMethod.GET)
	public int orderCount(String userId) {
		int count = 0;
		if(StringUtils.isNoneBlank(userId)){
			count = ordersService.orderTotalCount(userId);
		}
		return count;
	}
	
	@ApiOperation(value = "查询栏目的所有内容 (小程序首页)")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO home(String userId,String columnCode,String cityCode) {
		AssertUtil.notBlank(columnCode, "columnCode is required.");
		return columnService.home(userId, columnCode, cityCode);
	}
	
	
	@ApiOperation(value = "查询趣农庄栏目")
	@RequestMapping(value = "/shop/modules",method = RequestMethod.GET)
	public ListVO ShopModules(String locations, String coordsys, String columnCode, String modulesCode,int pageNumber, int maxPageRow) {
		return columnService.ShopModules(locations, coordsys, columnCode, modulesCode, pageNumber, maxPageRow);
	}
}
